<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>网络分析服务-服务区分析</title>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
<script type="text/javascript" src="../../dist/include-leaflet.js"></script>
<script type="text/javascript">
    var host = window.isLocal ? document.location.protocol + "//" + document.location.host : "http://support.supermap.com.cn:8090";
    var map, resultLayer, service, parameter, marker,
        baseUrl = host + "/iserver/services/map-changchun/rest/maps/长春市区图",
        serviceUrl = host + "/iserver/services/transportationanalyst-sample/rest/networkanalyst/RoadNet@Changchun";
    map = L.map('map', {
        crs: L.CRS.NonEarthCRS({
            bounds: L.bounds([48.4, -7668.25], [8958.85, -55.58]),
            origin: L.point(48.4, -55.58)
        }),
        center: [-3500, 5200],
        maxZoom: 18,
        zoom: 3
    });
    L.supermap.tiledMapLayer(baseUrl, {noWrap: true}).addTo(map);
    findServiceAreas();

    function findServiceAreas() {
        //添加中心点
        marker = L.marker([-3375, 5605]).addTo(map);
        var resultSetting = new SuperMap.TransportationAnalystResultSetting({
            returnEdgeFeatures: true,
            returnEdgeGeometry: true,
            returnEdgeIDs: true,
            returnNodeFeatures: true,
            returnNodeGeometry: true,
            returnNodeIDs: true,
            returnPathGuides: true,
            returnRoutes: true
        });
        var analystParameter = new SuperMap.TransportationAnalystParameter({
            resultSetting: resultSetting,
            weightFieldName: "length"
        });
        parameter = new SuperMap.FindServiceAreasParameters({
            centers: [marker.getLatLng()],
            isAnalyzeById: false,
            parameter: analystParameter
        });
        service = L.supermap.networkAnalystService(serviceUrl);
        resultLayer = L.featureGroup().addTo(map);
        parameter.weights = [400 + Math.random() * 100];
        service.findServiceAreas(parameter, function (serviceResult) {
            var result = serviceResult.result;
            result.serviceAreaList.map(function (serviceArea) {
                resultLayer.addLayer(L.geoJSON(serviceArea.serviceRegion));
            });

        });
    }
</script>
</body>
</html>